package 数据结构.单调栈;

import java.util.Stack;

/**
 * @description:
 * @author: ywk
 * @date: 2020-12-28
 */
public class 身高比 {
    public static int[] nextGreaterElement(int[] nums) {
        int[] arr = new int[nums.length];
        Stack<Integer> stack = new Stack();
        for (int i = nums.length - 1; i >= 0; i--) {
            while (!stack.isEmpty() && stack.peek() <= nums[i]) {
                stack.pop();
            }
            arr[i] = stack.empty() ? -1 : stack.peek();
            stack.push(nums[i]);
        }
        return arr;
    }

    public static void main(String[] args) {
        nextGreaterElement(new int[]{2, 1, 2, 4, 3});
    }
}
